<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>canvas 转图片</title>
    <style>
        body{
            background: #050504;
        }
    </style>
</head>
<body>
<canvas id="canvas" width="300" height="425"></canvas>
<img id="imgDom">
<script>
    const canvas=document.getElementById('canvas');
    const ctx=canvas.getContext('2d');
    const imgDom=document.getElementById('imgDom');
    const img = new Image();
    img.setAttribute("crossOrigin",'Anonymous');

    img.src = "https://ycg-1251509803.image.myqcloud.com/upload/articles/pic-9cb9098c-c226-42e8-9318-eb448ede26d6.jpg";
    img.onload = function() {
        ctx.drawImage(img, 0, 0, 300, 425);
        imgDom.src = canvas.toDataURL();

    }
</script>
</body>
</html>

